package com.shd.edanpei.presenter;

import com.shd.edanpei.base.BasePresenterImpl;
import com.shd.edanpei.base.network.api.ApiCreator;
import com.shd.edanpei.base.network.rx.BaseObserver;
import com.shd.edanpei.base.network.rx.RxTransformer;
import com.shd.edanpei.bean.MeNeedModel;
import com.shd.edanpei.presenter.contract.NeedDetailsContract;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by mc on 2018/10/18.
 * yang-wen-wen
 */

public class NeedDetailsPresenter extends BasePresenterImpl<NeedDetailsContract.NeedDetailsIView>
        implements NeedDetailsContract.NeedDetailsIPresenter {

    public NeedDetailsPresenter(NeedDetailsContract.NeedDetailsIView mView) {
        super(mView);
    }

    @Override
    public void getData(int id) {
        mBaseIView.showLoading("");
        ApiCreator.getApi().needDetails(id)
                .compose(RxTransformer.<MeNeedModel>errorHandle())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MeNeedModel>() {
                    @Override
                    protected void onSuccess(MeNeedModel data) {
                        mBaseIView.setData(data);
                    }

                    @Override
                    public void onFinish() {
                        mBaseIView.stopLoading();
                    }
                });
    }
}
